<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 冒泡排序
      let arr = [3, 2, 5, 1, 4]
      for (let i = 0; i < arr.length - 1; i++) {
        //外层循环控制对边几轮
        for (let j = 0; j < arr.length - 1 - i; j++) {
          //内层循环控制每轮对比几次，对比的数字次数为每轮减一次 例第一轮对比数组总个数减一次
          if (arr[j] > arr[j + 1]) {
            let temp = arr[j]
            arr[j] = arr[j + 1]
            arr[j + 1] = temp
          }
        }
      }
      document.write(arr)
      // arr.sort(function(a,b){
      //   return a-b
      // })
      // document.write(arr)
    </script>
  </body>
</html>
